var content = require('../../../public/content');
var template = require('template');

return extend(content, {
    target:'#subject-manage',
    path:'/subject-manage/',
    data:{
        title:'科目管理',
        menus:[{
            type:1,
            name:'资产'
        }, {
            type:2,
            name:'负债'
        }, {
            type:3,
            name:'共同'
        }, {
            type:4,
            name:'权益'
        }, {
            type:5,
            name:'成本'
        }, {
            type:6,
            name:'损益'
        }]
    },
    template:{
        left:renders({
            <%include 'menu'%>
        })
    },
    events:{
        'click .m-tabmenu > a':'scrollTo'
    },
    grid:{
        paging:{
            url:sourceHttp,
            isPage:false,
            pCount:200
        },
        columns:[{
            title:'编码',
            field:'id',
            className:'f-tal brn',
            filter:function(value){
                return value
            }
        }, {
            title:'',
            width:50,
            className:'bln e-p0 f-tal',
            filter:function(value){
                return renders({
                    <a class="j-add e-mr5 f-cblue" title="批量新增">
                        <i class="iconfont">&#xe63a;</i>
                    </a>
                    <a class="j-add e-ml5 f-cblue" title="禁用">
                        <i class="iconfont">&#xe64d;</i>
                    </a>
                })
            }
        }, {
            title:'名称',
            align:'left',
            className:'f-tal',
            width:'40%',
            field:'buname',
        }, {
            title:'方向',
            field:'buname',
            width:50,
            filter:function(){
                return '借'
            }
        }, {
            title:'操作',
            width:'25%',
            filter:function(){
                return renders({
                    <a class="j-add e-ml20 f-cblue">
                        <i class="iconfont">&#xe63a;</i>
                        <em class="e-ml5">新增</em>
                    </a>
                    <a class="j-add e-ml20 f-cblue">
                        <i class="iconfont">&#xe64d;</i>
                        <em class="e-ml5">修改</em>
                    </a>
                    <a class="j-add e-ml20 f-cblue">
                        <i class="iconfont">&#xe63d;</i>
                        <em class="e-ml5">删除</em>
                    </a>
                })
            }
        }],
        onRender:function(self){
            var menus = this.data.menus;
            Nui.each(menus, function(v, k){
                Nui.each(self.list, function(_v, _k){
                    if(v.top === undefined && k*15 === _k /*v.type == _v.type*/){
                        v.top = _k * 35;
                        return false;
                    }
                })
            })
            this.element.find('.m-tabmenu').replaceWith(template.render(this.template.menu, this.data))
        },
        onScroll:function(self, e, elem, data){
            var arr = [].concat(self.router.data.menus);
            Nui.each(arr.reverse(), function(v, k){
                if(data.top >= v.top){
                    self.router.header.find('.m-tabmenu a[type="'+ v.type +'"]').addClass('s-crt').siblings().removeClass('s-crt')
                    return false;
                }
            })
        }
    },
    scrollTo:function(e, elem){
        this.datagrid.scrollTo(0, elem.attr('top'));
        setTimeout(function(){
            elem.addClass('s-crt').siblings().removeClass('s-crt')
        })
    }
})